import { describe, it, expect, beforeAll, afterAll } from "vitest"; import fs from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import { GET as getMonths } from "./route.js"; let tmpRoot; beforeAll(async () => { tmpRoot = await fs.mkdtemp(path.join(os.tmpdir(), "api-months-")); process.env.NAS_ROOT_PATH = tmpRoot; // tmpRoot/NL01/2024/10 await fs.mkdir(path.join(tmpRoot, "NL01", "2024", "10"), { recursive: true, }); }); afterAll(async () => { await fs.rm(tmpRoot, { recursive: true, force: true }); }); describe("GET /api/branches/[branch]/[year]/months", () => { it("returns months for a valid branch/year", async () => { const req = new Request("http://localhost/api/branches/NL01/2024/months"); const ctx = { params: Promise.resolve({ branch: "NL01", year: "2024" }), }; const res = await getMonths(req, ctx); expect(res.status).toBe(200); const body = await res.json(); expect(body).toEqual({ branch: "NL01", year: "2024", months: ["10"], }); }); it("returns 400 when branch or year is missing", async () => { const req = new Request("http://localhost/api/branches/NL01/2024/months"); const ctx = { params: Promise.resolve({ branch: "NL01" }), // year missing }; const res = await getMonths(req, ctx); expect(res.status).toBe(400); const body = await res.json(); expect(body.error).toBe("branch oder year fehlt"); }); });